package com.ming.easyDevelop.controller;

import com.ming.easyDevelop.controller.base.BaseController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.ming.easyDevelop.service.CouponsService;
import com.ming.easyDevelop.controller.base.ValidListBean;
import javax.validation.Valid;
import com.ming.easyDevelop.entity.po.Coupons;
import com.ming.easyDevelop.entity.vo.ResponseVo;
import com.ming.easyDevelop.entity.query.CouponsQuery;
import java.util.List;
/**
 * @Description  Controller API
 * @Author ming
 * @Date 2024/07/10
 */
@RequestMapping("/api/coupons")
@RestController
public class CouponsController extends BaseController {
	@Resource
	private CouponsService couponsService;

	@RequestMapping("/list")
	public ResponseVo getDataList(CouponsQuery query){
		return getSuccessResponseVo(this.couponsService.findListByParam(query));
	}
	@PostMapping("/add")
	public ResponseVo add(@Valid @RequestBody Coupons bean){
		this.couponsService.add(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdate")
	public ResponseVo addOrUpdate(@Valid @RequestBody Coupons bean){
		this.couponsService.addOrUpdate(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addBatch")
	public ResponseVo addBatch(@RequestBody ValidListBean<Coupons> list){
		this.couponsService.addBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdateBatch")
	public ResponseVo addOrUpdateBatch(@RequestBody ValidListBean<Coupons> list){
		this.couponsService.addOrUpdateBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据CouponCode查询
	 */
	@GetMapping("/couponCode")
	public ResponseVo getByCouponCode(String couponCode){
		return getSuccessResponseVo(this.couponsService.getByCouponCode(couponCode));
	}

	/**
	 * 根据CouponCode更新
	 */
	@PutMapping("/couponCode")
	public ResponseVo updateByCouponCode(@Valid Coupons bean, String couponCode){
		this.couponsService.updateByCouponCode(bean,couponCode);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据CouponCode删除
	 */
	@DeleteMapping("/couponCode")
	public ResponseVo deleteByCouponCode(String couponCode){
		this.couponsService.deleteByCouponCode(couponCode);
		return getSuccessResponseVo(null);
	}

}